package org.paic.d.test

import org.paic.d.D

class DTest extends GroovyTestCase {

	void setUp(){
		def d = D.gen()

		String sql = '''
		create table if not exists t1 (
			id int auto_increment primary key, 
			name varchar(20),
			age int
		)
		'''
		d.exe(sql)
	}

	void tearDown(){
		def d = D.gen()

		String sql = '''
		drop table t1
		'''
		d.exe(sql)
	}

	void testAll(){
		def d = D.gen()

		int id = d.add([name: 'kerry', age: 27], 't1')
		assert id == 1

		d.update([id: 1, name: 'kerry', age: 28], 't1', null)

		def r = [name: 'kerry']

		def ll = d.query('select name from t1')
		assert ll[0] == r

		def ll2 = d.query('select name from t1 where id = ?', [1])
		assert ll2[0] == r

		def item = d.queryMap('select name from t1 where id = 1')
		assert item == r

		def item2 = d.queryMap('select name from t1 where id = ?', [1])
		assert item2 == r

		def pager = d.pagi('select name from t1 where id = ?', [1], 1, 10)
		assert pager.totalCount == 1
	}
}